home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / Collision][ demo ƒ / sApple.c < prev    next >
Text File  |  1995-01-16  |  2KB  |  88 lines

  1. /* Apple sprite for SATcollision][ */
  2. /* No, it has nothing to do with old Apple computers :-) */
  3.  
  4. /* unit sApple; */
  5.  
  6. #include "SAT.h"
  7. #include "Collision][.h"
  8.  
  9.     static Handle    nammSound, bliaehSound;
  10.     static FacePtr    goodFace, badFace;
  11.     static FacePtr    coreDump;
  12.  
  13.  
  14.     void InitApple()
  15.     {
  16.         int i;
  17.         
  18.         nammSound = SATGetNamedSound("\pnamm");
  19.         bliaehSound = SATGetNamedSound("\pbliaeh");
  20.         goodFace = SATGetFace(132);
  21.         badFace = SATGetFace(133);
  22.         coreDump = SATGetFace(135);
  23.     }
  24.  
  25.     pascal void SetupApple (SpritePtr me)
  26.     {
  27.         me->speed.h = 1 + SATRand(3);
  28.         me->kind = -2; /*Enemy kind*/
  29.         me->face = goodFace;
  30.         SetRect(&me->hotRect, 0, 0, 32, 32);
  31.         me->task = HandleApple;
  32.         me->hitTask = HitApple;
  33.     }
  34.  
  35. /*We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.*/
  36. /*Note that the "kind" field is not modified my SAT since we are not using KindCollision!*/
  37.  
  38.     pascal void HandleApple (SpritePtr me)
  39.     {
  40.         switch (me->kind) {
  41.             case -2: 
  42.                 me->face = goodFace;
  43.                 break;
  44.             case -3: 
  45.                 me->face = badFace;
  46.                 break;
  47.         }; /*switch*/
  48.  
  49.         me->position.h = me->position.h + me->speed.h;
  50.         if (me->position.h > gSAT.offSizeH - 16)
  51.             {
  52.                 me->speed.h = -1 - SATRand(3);
  53.                 if (SATRand(2) == 0)
  54.                     me->kind = -3;
  55.                 else
  56.                     me->kind = -2;
  57.             };
  58.         if (me->position.h < -16)
  59.             {
  60.                 me->speed.h = 1 + SATRand(3);
  61.                 if (SATRand(2) == 0)
  62.                     me->kind = -3;
  63.                 else
  64.                     me->kind = -2;
  65.             };
  66.     }
  67.  
  68.     pascal void HitApple(SpritePtr me, SpritePtr him)
  69.     {
  70.         if (him->task == &HandleApple)
  71.             me->kind = -3; /*Colliding apples corrupt each other!*/
  72.         else
  73. /*If "him" is not an apple, then it must be the player!*/
  74.             if (him->mode >= 0) /*if the player feels bad, don't eat*/
  75.                 switch (me->kind) {
  76.                     case -2:
  77.                             SATSoundPlay(nammSound, 1, false);
  78.                             me->task = nil;
  79.                             him->mode = 25;
  80.                             SATPlotFace(coreDump, nil, me->position, true);
  81.                             break;
  82.                     case -3: /*Bad apple, make player feel bad.*/
  83.                             him->mode = -20;
  84.                             SATSoundPlay(bliaehSound, 2, false);
  85.                             break;
  86.                 };
  87.     }
  88.